package com.letian.web.controller.record;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.letian.common.annotation.Log;
import com.letian.common.core.controller.BaseController;
import com.letian.common.core.domain.AjaxResult;
import com.letian.common.enums.BusinessType;
import com.letian.record.domain.RecordTask;
import com.letian.record.service.IRecordTaskService;
import com.letian.common.utils.poi.ExcelUtil;
import com.letian.common.core.page.TableDataInfo;

/**
 * 记录任务Controller
 * 
 * @author bmz
 * @date 2023-09-28
 */
@RestController
@RequestMapping("/record/task")
public class RecordTaskController extends BaseController
{
    @Autowired
    private IRecordTaskService recordTaskService;

    /**
     * 查询记录任务列表
     */
    @PreAuthorize("@ss.hasPermi('record:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordTask recordTask)
    {
        startPage();
        List<RecordTask> list = recordTaskService.selectRecordTaskList(recordTask);
        return getDataTable(list);
    }

    /**
     * 查询记录任务列表
     */
    @PreAuthorize("@ss.hasPermi('record:task:list')")
    @GetMapping("/my/list")
    public TableDataInfo myList(RecordTask recordTask)
    {
        startPage();
        recordTask.setOwner(getUsername());
        List<RecordTask> list = recordTaskService.selectRecordTaskList(recordTask);
        return getDataTable(list);
    }

    /**
     * 导出记录任务列表
     */
    @PreAuthorize("@ss.hasPermi('record:task:export')")
    @Log(title = "记录任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordTask recordTask)
    {
        List<RecordTask> list = recordTaskService.selectRecordTaskList(recordTask);
        ExcelUtil<RecordTask> util = new ExcelUtil<RecordTask>(RecordTask.class);
        util.exportExcel(response, list, "记录任务数据");
    }

    /**
     * 获取记录任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('record:task:query')")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId)
    {
        return success(recordTaskService.selectRecordTaskByTaskId(taskId));
    }

    /**
     * 新增记录任务
     */
    @PreAuthorize("@ss.hasPermi('record:task:add')")
    @Log(title = "记录任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordTask recordTask)
    {
        recordTask.setOwner(getUsername());
        recordTask.setCreateBy(getUsername());
        return toAjax(recordTaskService.insertRecordTask(recordTask));
    }

    /**
     * 修改记录任务
     */
    @PreAuthorize("@ss.hasPermi('record:task:edit')")
    @Log(title = "记录任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordTask recordTask)
    {
        recordTask.setUpdateBy(getUsername());
        return toAjax(recordTaskService.updateRecordTask(recordTask));
    }

    /**
     * 修改记录任务
     */
    @PreAuthorize("@ss.hasPermi('record:task:edit')")
    @Log(title = "记录任务", businessType = BusinessType.UPDATE)
    @PutMapping("/disableOrEnableTask/{taskId}")
    public AjaxResult disableOrEnableTask(@PathVariable Long taskId)
    {
        return toAjax(recordTaskService.disableOrEnableTask(taskId, getUsername()));
    }

    /**
     * 删除记录任务
     */
    @PreAuthorize("@ss.hasPermi('record:task:remove')")
    @Log(title = "记录任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds)
    {
        return toAjax(recordTaskService.deleteRecordTaskByTaskIds(taskIds));
    }
}
